// Copyright 2025 Google LLC.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "cbor/host_decoder.h"

#include <cstddef>
#include <cstdint>
#include <vector>

#include "gtest/gtest.h"

namespace proofs {
namespace {

// helper function to encode CBOR input bytes
static inline uint8_t X(uint8_t type, uint8_t count) {
  return (type << 5) | count;
}

TEST(HostDecoderTest, DecodeHost) {
  struct testcase {
    bool valid;
    std::vector<uint8_t> bytes;
  };

  struct testcase tests[31] = {
      // small atom tests
      {true, {0}},
      {true, {X(0, 22), 1}},
      {true, {X(0, 23), 0}},
      {true, {X(0, 24), 33}},
      {true, {X(0, 24), 34}},
      // Primitives
      {true, {X(7, 20)}},
      {true, {X(7, 21)}},
      {true, {X(7, 22)}},

      // a short string
      {true, {X(2, 3), 'f', 'o', 'o'}},

      // a long string:  header + next byte + string
      {true, {X(2, 24), 3, 0xff, 25, 31}},

      // TAG for date
      {true,
       {0xD9, 0x03, 0xEC, 0x6a, 0x31, 0x39, 0x37, 0x31, 0x2D, 0x30, 0x39, 0x2D,
        0x30, 0x31}},

      // uint type
      {true, {0x18, 0xAF}},

      // array with 4 string elements
      {true,
       {X(4, 4), 0x62, 'x', 'y', 0x63, '1', '.', '0', 0x62, 'a', 'b', 0x61,
        'c'}},

      // map with 3 entries, {string, int}
      {true, {X(5, 3), 0x62, 'x', 'y', 0x8, 0x61, 'a', 0x9, 0x61, 'b', 0xa}},

      // large map with 2 entries {int, array} with large array elements
      {true, {X(5, 0x18), 2, 0, 0x58, 0x2, 'a', 'b', 1, 0x58, 2, 'b', 'c'}},

      // recursive map of maps, keys of different types
      {true, {0xA2, 0xA1, 0xA1, 1, 1, 0xF4, 0x61, 'a', 0x61, 'b', 3, 4}},

      // real world example, 483b MSO from an MDOC
      {true,
       {0xA6, 0x67, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x63, 0x31, 0x2E,
        0x30, 0x6F, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74, 0x41, 0x6C, 0x67, 0x6F,
        0x72, 0x69, 0x74, 0x68, 0x6D, 0x67, 0x53, 0x48, 0x41, 0x2D, 0x32, 0x35,
        0x36, 0x67, 0x64, 0x6F, 0x63, 0x54, 0x79, 0x70, 0x65, 0x75, 0x6F, 0x72,
        0x67, 0x2E, 0x69, 0x73, 0x6F, 0x2E, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2E,
        0x35, 0x2E, 0x31, 0x2E, 0x6D, 0x44, 0x4C, 0x6C, 0x76, 0x61, 0x6C, 0x75,
        0x65, 0x44, 0x69, 0x67, 0x65, 0x73, 0x74, 0x73, 0xA1, 0x71, 0x6F, 0x72,
        0x67, 0x2E, 0x69, 0x73, 0x6F, 0x2E, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2E,
        0x35, 0x2E, 0x31, 0xA5, 0x01, 0x58, 0x20, 0xAD, 0xF6, 0xA3, 0x33, 0x03,
        0x6A, 0xDE, 0xFC, 0x48, 0x90, 0xDF, 0x38, 0xE0, 0xF7, 0x37, 0x22, 0x90,
        0x85, 0xA9, 0xB0, 0xBA, 0x7C, 0x07, 0x19, 0xD3, 0x92, 0x40, 0x5D, 0x74,
        0x46, 0x23, 0x77, 0x02, 0x58, 0x20, 0xA0, 0xA1, 0x4A, 0x5A, 0xA1, 0xB3,
        0x36, 0x84, 0x4D, 0x8F, 0x8D, 0x14, 0x8E, 0xD4, 0x4F, 0xD2, 0xCC, 0xC6,
        0x6F, 0x54, 0xD8, 0x78, 0x2B, 0x70, 0xFB, 0x77, 0x13, 0xFB, 0x3C, 0x93,
        0xF5, 0x56, 0x03, 0x58, 0x20, 0x97, 0xB0, 0x18, 0x4E, 0xDD, 0xE3, 0x99,
        0xCB, 0x7D, 0xEA, 0x2D, 0x7D, 0x27, 0x9A, 0x45, 0x69, 0x90, 0xD9, 0xF3,
        0x12, 0x46, 0x71, 0x63, 0x78, 0x7E, 0x1B, 0xA7, 0x66, 0x0A, 0x5C, 0x08,
        0x6F, 0x04, 0x58, 0x20, 0xAF, 0x0B, 0x9F, 0xE7, 0x24, 0x5C, 0xA9, 0xA5,
        0x9F, 0x64, 0xB1, 0xAA, 0x82, 0xCC, 0x2C, 0x1A, 0xB1, 0x38, 0x6F, 0x77,
        0x95, 0x64, 0x93, 0x83, 0x62, 0x97, 0xC8, 0xA8, 0x4D, 0x2A, 0xE0, 0xB4,
        0x00, 0x58, 0x20, 0x0D, 0x98, 0x54, 0xDB, 0x51, 0x48, 0x6F, 0xF4, 0x49,
        0x07, 0xBC, 0x61, 0x4F, 0xFA, 0xEA, 0x93, 0xDA, 0xE1, 0xA8, 0x9E, 0xAD,
        0x40, 0x26, 0x3F, 0x90, 0x1A, 0xE6, 0xCE, 0x41, 0x26, 0x46, 0x21, 0x6D,
        0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4B, 0x65, 0x79, 0x49, 0x6E, 0x66,
        0x6F, 0xA1, 0x69, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4B, 0x65, 0x79,
        0xA4, 0x01, 0x02, 0x20, 0x01, 0x21, 0x58, 0x20, 0xC3, 0x14, 0xA7, 0xAB,
        0xBA, 0x07, 0xE4, 0x0E, 0x64, 0xAE, 0x87, 0xDB, 0x4A, 0xD9, 0x71, 0x80,
        0x13, 0xFD, 0x39, 0x8E, 0x6E, 0x23, 0x17, 0xB3, 0x04, 0xF5, 0x7F, 0xC9,
        0xAC, 0xCA, 0xB9, 0xF5, 0x22, 0x58, 0x20, 0xED, 0xB8, 0xB0, 0x23, 0x0C,
        0xCC, 0x98, 0xDD, 0x42, 0xCD, 0xFF, 0x89, 0xA8, 0xD1, 0xE2, 0x5F, 0xF8,
        0xD1, 0xA7, 0xFA, 0x38, 0x9E, 0x92, 0xDC, 0x8F, 0x01, 0xAF, 0x98, 0x5A,
        0x79, 0xEF, 0xCC, 0x6C, 0x76, 0x61, 0x6C, 0x69, 0x64, 0x69, 0x74, 0x79,
        0x49, 0x6E, 0x66, 0x6F, 0xA3, 0x66, 0x73, 0x69, 0x67, 0x6E, 0x65, 0x64,
        0xC0, 0x74, 0x32, 0x30, 0x32, 0x34, 0x2D, 0x30, 0x31, 0x2D, 0x32, 0x35,
        0x54, 0x32, 0x31, 0x3A, 0x31, 0x32, 0x3A, 0x35, 0x39, 0x5A, 0x69, 0x76,
        0x61, 0x6C, 0x69, 0x64, 0x46, 0x72, 0x6F, 0x6D, 0xC0, 0x74, 0x32, 0x30,
        0x32, 0x34, 0x2D, 0x30, 0x31, 0x2D, 0x32, 0x35, 0x54, 0x32, 0x31, 0x3A,
        0x31, 0x32, 0x3A, 0x35, 0x39, 0x5A, 0x6A, 0x76, 0x61, 0x6C, 0x69, 0x64,
        0x55, 0x6E, 0x74, 0x69, 0x6C, 0xC0, 0x74, 0x32, 0x30, 0x32, 0x34, 0x2D,
        0x30, 0x32, 0x2D, 0x32, 0x34, 0x54, 0x32, 0x31, 0x3A, 0x31, 0x32, 0x3A,
        0x35, 0x39, 0x5a}},

      // Attribute encoding with date_of_birth:full-date
      {true,
       {0xA4, 0x68, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74, 0x49, 0x44, 0x18, 0x24,
        0x66, 0x72, 0x61, 0x6E, 0x64, 0x6F, 0x6D, 0x50, 0xAC, 0x3E, 0x67, 0x95,
        0xBA, 0xE2, 0x02, 0x37, 0x4D, 0xEE, 0xA4, 0x78, 0xE9, 0x37, 0x7E, 0xE5,
        0x71, 0x65, 0x6C, 0x65, 0x6D, 0x65, 0x6E, 0x74, 0x49, 0x64, 0x65, 0x6E,
        0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x6A, 0x62, 0x69, 0x72, 0x74, 0x68,
        0x5F, 0x64, 0x61, 0x74, 0x65, 0x6C, 0x65, 0x6C, 0x65, 0x6D, 0x65, 0x6E,
        0x74, 0x56, 0x61, 0x6C, 0x75, 0x65, 0xD9, 0x03, 0xEC, 0x6A, 0x31, 0x39,
        0x37, 0x31, 0x2D, 0x30, 0x39, 0x2D, 0x30, 0x31}},

      // Attribute encoding with Height:uint
      {true, {0xA4, 0x68, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74, 0x49, 0x44, 0x18,
              0x23, 0x66, 0x72, 0x61, 0x6E, 0x64, 0x6F, 0x6D, 0x50, 0x1D, 0x77,
              0xDC, 0x10, 0x24, 0xD7, 0xC0, 0xC9, 0x63, 0x8B, 0x21, 0x60, 0x42,
              0xB9, 0x1C, 0xA3, 0x71, 0x65, 0x6C, 0x65, 0x6D, 0x65, 0x6E, 0x74,
              0x49, 0x64, 0x65, 0x6E, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x66,
              0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x6C, 0x65, 0x6C, 0x65, 0x6D,
              0x65, 0x6E, 0x74, 0x56, 0x61, 0x6C, 0x75, 0x65, 0x18, 0xAF}},

      // Attribute encoding with issue_date:fulldate
      {true,
       {0xA4, 0x68, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74, 0x49, 0x44, 0x18, 0x1E,
        0x66, 0x72, 0x61, 0x6E, 0x64, 0x6F, 0x6D, 0x50, 0xDD, 0xD2, 0x56, 0x45,
        0xC2, 0xA3, 0xDD, 0x69, 0xF8, 0x9F, 0xBF, 0x01, 0x72, 0x99, 0x53, 0x81,
        0x71, 0x65, 0x6C, 0x65, 0x6D, 0x65, 0x6E, 0x74, 0x49, 0x64, 0x65, 0x6E,
        0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x6A, 0x69, 0x73, 0x73, 0x75, 0x65,
        0x5F, 0x64, 0x61, 0x74, 0x65, 0x6C, 0x65, 0x6C, 0x65, 0x6D, 0x65, 0x6E,
        0x74, 0x56, 0x61, 0x6C, 0x75, 0x65, 0xD9, 0x03, 0xEC, 0x6A, 0x32, 0x30,
        0x32, 0x34, 0x2D, 0x30, 0x33, 0x2D, 0x31, 0x35}},

      // Complex mdoc device response
      {true,
       {0xa3, 0x67, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x63, 0x31, 0x2e,
        0x30, 0x69, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x81,
        0xa3, 0x67, 0x64, 0x6f, 0x63, 0x54, 0x79, 0x70, 0x65, 0x75, 0x6f, 0x72,
        0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,
        0x35, 0x2e, 0x31, 0x2e, 0x6d, 0x44, 0x4c, 0x6c, 0x69, 0x73, 0x73, 0x75,
        0x65, 0x72, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xa2, 0x6a, 0x6e, 0x61,
        0x6d, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x73, 0xa1, 0x71, 0x6f, 0x72,
        0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2e,
        0x35, 0x2e, 0x31, 0x84, 0xd8, 0x18, 0x58, 0x59, 0xa4, 0x68, 0x64, 0x69,
        0x67, 0x65, 0x73, 0x74, 0x49, 0x44, 0x04, 0x66, 0x72, 0x61, 0x6e, 0x64,
        0x6f, 0x6d, 0x50, 0xdb, 0x33, 0x69, 0x71, 0x1c, 0x0b, 0xc9, 0x1d, 0x0a,
        0xee, 0x22, 0x50, 0x1c, 0x02, 0xe5, 0x25, 0x71, 0x65, 0x6c, 0x65, 0x6d,
        0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65,
        0x72, 0x6b, 0x66, 0x61, 0x6d, 0x69, 0x6c, 0x79, 0x5f, 0x6e, 0x61, 0x6d,
        0x65, 0x6c, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x56, 0x61, 0x6c,
        0x75, 0x65, 0x6a, 0x4d, 0x75, 0x73, 0x74, 0x65, 0x72, 0x6d, 0x61, 0x6e,
        0x6e, 0xd8, 0x18, 0x58, 0x53, 0xa4, 0x68, 0x64, 0x69, 0x67, 0x65, 0x73,
        0x74, 0x49, 0x44, 0x02, 0x66, 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x50,
        0x43, 0x04, 0x12, 0x81, 0xc0, 0x63, 0x1c, 0x50, 0x59, 0x35, 0x91, 0x39,
        0x77, 0x4f, 0x1e, 0xb4, 0x71, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74,
        0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x6a, 0x67,
        0x69, 0x76, 0x65, 0x6e, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x6c, 0x65, 0x6c,
        0x65, 0x6d, 0x65, 0x6e, 0x74, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x65, 0x45,
        0x72, 0x69, 0x6b, 0x61, 0xd8, 0x18, 0x58, 0x5c, 0xa4, 0x68, 0x64, 0x69,
        0x67, 0x65, 0x73, 0x74, 0x49, 0x44, 0x18, 0x24, 0x66, 0x72, 0x61, 0x6e,
        0x64, 0x6f, 0x6d, 0x50, 0xac, 0x3e, 0x67, 0x95, 0xba, 0xe2, 0x02, 0x37,
        0x4d, 0xee, 0xa4, 0x78, 0xe9, 0x37, 0x7e, 0xe5, 0x71, 0x65, 0x6c, 0x65,
        0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69,
        0x65, 0x72, 0x6a, 0x62, 0x69, 0x72, 0x74, 0x68, 0x5f, 0x64, 0x61, 0x74,
        0x65, 0x6c, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x56, 0x61, 0x6c,
        0x75, 0x65, 0xd9, 0x03, 0xec, 0x6a, 0x31, 0x39, 0x37, 0x31, 0x2d, 0x30,
        0x39, 0x2d, 0x30, 0x31, 0xd8, 0x18, 0x58, 0x4f, 0xa4, 0x68, 0x64, 0x69,
        0x67, 0x65, 0x73, 0x74, 0x49, 0x44, 0x07, 0x66, 0x72, 0x61, 0x6e, 0x64,
        0x6f, 0x6d, 0x50, 0xc5, 0xf0, 0x66, 0x8b, 0xb8, 0x48, 0x23, 0x5c, 0x8d,
        0x73, 0x79, 0x05, 0xa1, 0x01, 0x4f, 0x18, 0x71, 0x65, 0x6c, 0x65, 0x6d,
        0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65,
        0x72, 0x6b, 0x61, 0x67, 0x65, 0x5f, 0x6f, 0x76, 0x65, 0x72, 0x5f, 0x32,
        0x31, 0x6c, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x56, 0x61, 0x6c,
        0x75, 0x65, 0xf5, 0x6a, 0x69, 0x73, 0x73, 0x75, 0x65, 0x72, 0x41, 0x75,
        0x74, 0x68, 0x84, 0x43, 0xa1, 0x01, 0x26, 0xa1, 0x18, 0x21, 0x59, 0x02,
        0x83, 0x30, 0x82, 0x02, 0x7f, 0x30, 0x82, 0x02, 0x25, 0xa0, 0x03, 0x02,
        0x01, 0x02, 0x02, 0x10, 0x35, 0x00, 0xba, 0x9b, 0xef, 0xd9, 0x1c, 0xb9,
        0xda, 0x79, 0x05, 0xff, 0xef, 0x18, 0xbe, 0x8a, 0x30, 0x0a, 0x06, 0x08,
        0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x30, 0x39, 0x31, 0x0b,
        0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x54, 0x31,
        0x2a, 0x30, 0x28, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x21, 0x4f, 0x57,
        0x46, 0x20, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x20, 0x43,
        0x72, 0x65, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x20, 0x54, 0x45,
        0x53, 0x54, 0x20, 0x49, 0x41, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x32,
        0x34, 0x30, 0x39, 0x30, 0x32, 0x31, 0x37, 0x32, 0x31, 0x31, 0x33, 0x5a,
        0x17, 0x0d, 0x32, 0x35, 0x30, 0x39, 0x30, 0x32, 0x31, 0x37, 0x32, 0x31,
        0x31, 0x33, 0x5a, 0x30, 0x37, 0x31, 0x28, 0x30, 0x26, 0x06, 0x03, 0x55,
        0x04, 0x03, 0x0c, 0x1f, 0x4f, 0x57, 0x46, 0x20, 0x49, 0x64, 0x65, 0x6e,
        0x74, 0x69, 0x74, 0x79, 0x20, 0x43, 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74,
        0x69, 0x61, 0x6c, 0x20, 0x54, 0x45, 0x53, 0x54, 0x20, 0x44, 0x53, 0x31,
        0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x54,
        0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02,
        0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03,
        0x42, 0x00, 0x04, 0xdc, 0x1c, 0x1f, 0x55, 0xcf, 0xf4, 0xcd, 0x5c, 0x76,
        0xcf, 0x41, 0x69, 0x27, 0x8f, 0x72, 0x17, 0x66, 0x7f, 0x86, 0xee, 0x81,
        0xd8, 0x66, 0x9b, 0x63, 0xf2, 0xe1, 0x9b, 0xc1, 0x2a, 0x0c, 0x9f, 0x12,
        0x35, 0x5d, 0xd0, 0x38, 0x5f, 0xed, 0x3b, 0xc3, 0x3b, 0xed, 0xc9, 0x78,
        0x1b, 0x9a, 0xad, 0x47, 0xb3, 0x3e, 0x4c, 0x24, 0x70, 0x4b, 0x8d, 0x14,
        0x28, 0x8b, 0x1b, 0x3c, 0xb4, 0x5c, 0x28, 0xa3, 0x82, 0x01, 0x0f, 0x30,
        0x82, 0x01, 0x0b, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16,
        0x04, 0x14, 0x13, 0x09, 0xce, 0x86, 0x0b, 0x9d, 0xff, 0xbc, 0x85, 0x99,
        0x28, 0x3a, 0x1d, 0xd9, 0xc1, 0xf3, 0x55, 0x6a, 0x63, 0xf1, 0x30, 0x1f,
        0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x3c,
        0xc0, 0x46, 0x99, 0x0e, 0x93, 0x42, 0x85, 0x46, 0x6d, 0xf6, 0xc6, 0xe0,
        0x9a, 0xe3, 0xe3, 0x68, 0xdf, 0x2b, 0x0e, 0x30, 0x0e, 0x06, 0x03, 0x55,
        0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x07, 0x80, 0x30,
        0x15, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x01, 0x01, 0xff, 0x04, 0x0b, 0x30,
        0x09, 0x06, 0x07, 0x28, 0x81, 0x8c, 0x5d, 0x05, 0x01, 0x02, 0x30, 0x54,
        0x06, 0x03, 0x55, 0x1d, 0x1f, 0x04, 0x4d, 0x04, 0x4b, 0x30, 0x49, 0x30,
        0x47, 0xa0, 0x45, 0xa0, 0x43, 0x86, 0x41, 0x68, 0x74, 0x74, 0x70, 0x73,
        0x3a, 0x2f, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f,
        0x6d, 0x2f, 0x6f, 0x70, 0x65, 0x6e, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74,
        0x2d, 0x66, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2d,
        0x6c, 0x61, 0x62, 0x73, 0x2f, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74,
        0x79, 0x2d, 0x63, 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c,
        0x30, 0x4c, 0x06, 0x03, 0x55, 0x1d, 0x12, 0x04, 0x45, 0x04, 0x43, 0x86,
        0x41, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x67, 0x69, 0x74,
        0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6f, 0x70, 0x65, 0x6e,
        0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x2d, 0x66, 0x6f, 0x75, 0x6e, 0x64,
        0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2d, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x69,
        0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2d, 0x63, 0x72, 0x65, 0x64,
        0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86,
        0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x48, 0x00, 0x30, 0x45, 0x02,
        0x21, 0x00, 0xcc, 0x61, 0x2d, 0xb2, 0xda, 0x22, 0x60, 0x9b, 0xf0, 0xa9,
        0xeb, 0xea, 0x39, 0xa9, 0x05, 0x74, 0xfa, 0xc6, 0xd1, 0xb0, 0xed, 0x8b,
        0x8b, 0xe0, 0x45, 0x27, 0x3e, 0xc7, 0x27, 0x6f, 0x64, 0x0c, 0x02, 0x20,
        0x7f, 0x21, 0x44, 0x30, 0x13, 0x45, 0x54, 0x40, 0x93, 0x53, 0xb4, 0xb7,
        0x4c, 0x4b, 0x64, 0x52, 0x64, 0x15, 0x81, 0x6d, 0x2f, 0xcb, 0x43, 0x29,
        0x57, 0x0c, 0x62, 0xd5, 0x56, 0x27, 0x2b, 0x54, 0x59, 0x06, 0xea, 0xd8,
        0x18, 0x59, 0x06, 0xe5, 0xa6, 0x67, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f,
        0x6e, 0x63, 0x31, 0x2e, 0x30, 0x6f, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74,
        0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x67, 0x53, 0x48,
        0x41, 0x2d, 0x32, 0x35, 0x36, 0x67, 0x64, 0x6f, 0x63, 0x54, 0x79, 0x70,
        0x65, 0x75, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38,
        0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0x2e, 0x6d, 0x44, 0x4c, 0x6c,
        0x76, 0x61, 0x6c, 0x75, 0x65, 0x44, 0x69, 0x67, 0x65, 0x73, 0x74, 0x73,
        0xa2, 0x71, 0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38,
        0x30, 0x31, 0x33, 0x2e, 0x35, 0x2e, 0x31, 0xb8, 0x22, 0x04, 0x58, 0x20,
        0x89, 0x34, 0x22, 0xe8, 0xf3, 0xb6, 0xc5, 0xa2, 0x8d, 0xb0, 0x97, 0xe7,
        0x9f, 0x4e, 0xf6, 0x10, 0x0b, 0xe5, 0xdb, 0x8a, 0x50, 0x34, 0xa4, 0xc2,
        0x94, 0x8d, 0x56, 0xf3, 0x66, 0x2a, 0x49, 0xa8, 0x02, 0x58, 0x20, 0x89,
        0x92, 0x53, 0x94, 0xa6, 0x4d, 0x6e, 0xe7, 0x84, 0x33, 0x51, 0x43, 0x4c,
        0xc8, 0x31, 0x81, 0xac, 0x7a, 0x67, 0xb0, 0x4d, 0x9d, 0xc7, 0x98, 0x2b,
        0x82, 0xf7, 0x4a, 0x7e, 0x1b, 0x15, 0x44, 0x18, 0x24, 0x58, 0x20, 0xa1,
        0xb6, 0x69, 0xb9, 0x04, 0xc3, 0xad, 0x1d, 0x80, 0x69, 0xe4, 0xaf, 0x7c,
        0x68, 0x4d, 0xa9, 0xa9, 0xcc, 0xc1, 0x28, 0x1e, 0x4c, 0x42, 0xbf, 0xad,
        0x9b, 0x2b, 0xc2, 0xe6, 0xb0, 0x51, 0x52, 0x18, 0x22, 0x58, 0x20, 0x39,
        0x74, 0x12, 0xc0, 0xf7, 0x1b, 0x7a, 0xda, 0xa3, 0xc1, 0x3b, 0x92, 0x24,
        0xcb, 0xb4, 0xdb, 0xd7, 0x01, 0x10, 0xb0, 0x52, 0x20, 0x94, 0xab, 0xb8,
        0x65, 0xb6, 0x7a, 0x48, 0xe1, 0xd3, 0xc2, 0x17, 0x58, 0x20, 0x1c, 0xf5,
        0x5e, 0x81, 0x24, 0xc8, 0xf6, 0x68, 0x33, 0x8b, 0xec, 0xe3, 0x44, 0x85,
        0x58, 0x7e, 0x40, 0x4a, 0x90, 0xd8, 0x13, 0xd4, 0x18, 0xb1, 0xe5, 0xf5,
        0xf0, 0x18, 0x70, 0xd1, 0x73, 0xc1, 0x18, 0x18, 0x58, 0x20, 0x6b, 0xdf,
        0xb7, 0xbe, 0x77, 0xee, 0xa4, 0x3b, 0x94, 0xbc, 0x18, 0x26, 0x5c, 0x67,
        0xf6, 0xbe, 0xa0, 0x63, 0xd5, 0x51, 0xc6, 0xbb, 0xf4, 0x1f, 0x88, 0x1d,
        0xeb, 0x0e, 0xe9, 0x13, 0x8e, 0xda, 0x0d, 0x58, 0x20, 0x80, 0x31, 0xa8,
        0xa1, 0x70, 0xf8, 0xab, 0x9f, 0x93, 0x63, 0xbe, 0xc8, 0x69, 0x48, 0xe5,
        0x3e, 0x17, 0x0a, 0x3d, 0xf6, 0x14, 0x09, 0x36, 0x81, 0x92, 0x0e, 0x4b,
        0xf1, 0xd9, 0x52, 0xe6, 0x2d, 0x11, 0x58, 0x20, 0x7f, 0x5b, 0xf8, 0x80,
        0x9b, 0x20, 0xad, 0xd4, 0x02, 0x0e, 0x5e, 0xac, 0xa1, 0x8e, 0x0e, 0xc2,
        0x85, 0x4f, 0xfe, 0xfe, 0x53, 0x24, 0x66, 0xb8, 0xf5, 0xc9, 0x39, 0xee,
        0x32, 0x58, 0x1c, 0x47, 0x03, 0x58, 0x20, 0xf7, 0x50, 0xec, 0xb0, 0xd8,
        0x6d, 0x8e, 0xf4, 0x2b, 0x5a, 0xed, 0x30, 0x1d, 0xfe, 0x0f, 0x99, 0x90,
        0x91, 0x04, 0x43, 0x3d, 0x87, 0x35, 0x74, 0xc4, 0x04, 0x35, 0x38, 0x20,
        0x62, 0xcd, 0x16, 0x05, 0x58, 0x20, 0x06, 0x64, 0xee, 0xc2, 0x65, 0x78,
        0x1c, 0xb9, 0xf4, 0x4b, 0x53, 0xc1, 0x3e, 0xfd, 0xb5, 0x15, 0xb6, 0x77,
        0x7e, 0xa1, 0xd0, 0xee, 0x8c, 0x74, 0xdf, 0x1f, 0x00, 0xaa, 0x4a, 0x3e,
        0x32, 0xeb, 0x18, 0x19, 0x58, 0x20, 0x79, 0xa3, 0xa9, 0x89, 0x9c, 0x85,
        0xb5, 0x99, 0xcc, 0x65, 0xd8, 0xfd, 0xb0, 0x3a, 0x9e, 0x5c, 0x46, 0x68,
        0x64, 0x14, 0xea, 0x29, 0x5c, 0x79, 0xe8, 0x30, 0xfe, 0x60, 0xed, 0xa5,
        0x4f, 0x2f, 0x14, 0x58, 0x20, 0x4b, 0xe3, 0x95, 0xcd, 0x0a, 0x82, 0x60,
        0x2d, 0x55, 0x7a, 0xce, 0xd8, 0xc0, 0x1f, 0x61, 0xb9, 0x07, 0x84, 0x60,
        0xe5, 0x2b, 0x5a, 0x29, 0x1b, 0x30, 0x1d, 0x6a, 0x4e, 0xeb, 0xec, 0xc2,
        0x08, 0x18, 0x26, 0x58, 0x20, 0xbb, 0xf6, 0x1b, 0x0d, 0x24, 0xc7, 0x4b,
        0x96, 0x2f, 0x2c, 0x66, 0x85, 0x66, 0x2b, 0x1e, 0x13, 0xe8, 0xb5, 0xcf,
        0xd2, 0x00, 0xbf, 0x90, 0xd8, 0x7e, 0x51, 0x16, 0xc5, 0x99, 0x7e, 0x2c,
        0x2d, 0x00, 0x58, 0x20, 0x99, 0x1c, 0xb2, 0x52, 0xdd, 0x19, 0xb3, 0x4e,
        0x4a, 0x0b, 0x2b, 0xa9, 0xe4, 0xe6, 0x98, 0xc7, 0x48, 0xfe, 0x95, 0x2c,
        0x69, 0x82, 0x5e, 0x1d, 0xfa, 0xca, 0x6b, 0x98, 0xa2, 0x64, 0x3f, 0x68,
        0x18, 0x21, 0x58, 0x20, 0x80, 0xc6, 0x19, 0xc1, 0xf6, 0x3c, 0x18, 0x27,
        0x27, 0x60, 0x9c, 0x07, 0xc0, 0x49, 0x2d, 0x0c, 0x0d, 0xf9, 0xd3, 0xfe,
        0x76, 0xd5, 0x0c, 0x61, 0x66, 0x75, 0x0e, 0xab, 0x0a, 0x5c, 0x12, 0xf0,
        0x16, 0x58, 0x20, 0x43, 0x76, 0x35, 0x23, 0xa3, 0x39, 0x98, 0xb0, 0x8b,
        0x7d, 0x60, 0x82, 0x10, 0x90, 0x24, 0x06, 0xb1, 0x6b, 0xd1, 0x5a, 0x38,
        0x01, 0xed, 0x9e, 0x83, 0xa5, 0x80, 0xc3, 0x19, 0xd7, 0xc7, 0xa8, 0x0f,
        0x58, 0x20, 0x53, 0x58, 0xce, 0xea, 0xca, 0x35, 0x04, 0xa8, 0x74, 0x48,
        0xae, 0x86, 0x4d, 0x5c, 0x47, 0x2f, 0x2c, 0x46, 0xcd, 0x6c, 0x27, 0xb1,
        0x7e, 0x15, 0x1a, 0x03, 0x14, 0xd9, 0x6c, 0xf9, 0x07, 0x5d, 0x18, 0x23,
        0x58, 0x20, 0x42, 0x8b, 0xa3, 0xd6, 0x22, 0x4e, 0x62, 0xc6, 0x38, 0x66,
        0xb3, 0x61, 0xb3, 0x85, 0x2f, 0x2c, 0x2d, 0xc6, 0x7f, 0x4c, 0x3f, 0x72,
        0x00, 0x2b, 0xdf, 0x1b, 0xbb, 0x83, 0x11, 0x22, 0x50, 0xc8, 0x0e, 0x58,
        0x20, 0xb3, 0xdd, 0xfc, 0x41, 0x84, 0x91, 0x37, 0x16, 0x8d, 0xd9, 0xb3,
        0x08, 0xfd, 0x10, 0x3e, 0x1d, 0x6d, 0x27, 0x2e, 0xca, 0x73, 0x5f, 0x16,
        0xda, 0x2d, 0xdb, 0xb7, 0x3b, 0xaf, 0x2d, 0x35, 0x18, 0x18, 0x1b, 0x58,
        0x20, 0xf4, 0x0f, 0x8d, 0x7d, 0x0e, 0xad, 0xcf, 0xc2, 0x43, 0x47, 0xec,
        0xa8, 0x48, 0x7d, 0x0f, 0xc7, 0xf7, 0x38, 0xcf, 0xfd, 0x6b, 0x09, 0xe2,
        0x03, 0x4b, 0x61, 0xef, 0x65, 0x27, 0x5f, 0x2c, 0x30, 0x18, 0x20, 0x58,
        0x20, 0x94, 0xb3, 0xaf, 0xfc, 0x59, 0xda, 0x35, 0x4e, 0xf1, 0xbf, 0x76,
        0xbd, 0xb7, 0xad, 0xf1, 0x32, 0x18, 0x28, 0x06, 0xd8, 0x51, 0x24, 0x3d,
        0xea, 0xb4, 0x6b, 0xb7, 0xac, 0x67, 0xbb, 0x3b, 0xc3, 0x10, 0x58, 0x20,
        0xcd, 0x7e, 0x15, 0x02, 0xb2, 0x23, 0x2c, 0x24, 0x71, 0x43, 0x92, 0x52,
        0x0c, 0xd8, 0xa7, 0x92, 0x49, 0xbd, 0x1b, 0x9c, 0x1a, 0xbc, 0xf3, 0x2e,
        0x28, 0x3f, 0x9c, 0x02, 0xe9, 0x15, 0xc1, 0xa6, 0x0c, 0x58, 0x20, 0x00,
        0xbd, 0x49, 0x19, 0xa3, 0x16, 0xca, 0x8e, 0xa5, 0xde, 0x98, 0x6a, 0xe3,
        0x06, 0xa7, 0xef, 0x28, 0xdd, 0x65, 0x1e, 0x04, 0x57, 0xc2, 0x33, 0x99,
        0x9f, 0xe1, 0x45, 0xf4, 0x88, 0x2b, 0xba, 0x01, 0x58, 0x20, 0x96, 0x41,
        0x79, 0x66, 0x91, 0x03, 0x63, 0x3f, 0x18, 0xd4, 0x91, 0x09, 0x1d, 0xf2,
        0x6e, 0x64, 0xe6, 0xb8, 0xa3, 0x77, 0xdf, 0xfa, 0x1e, 0xf2, 0xd3, 0x4e,
        0x90, 0x45, 0x37, 0x57, 0xae, 0xaf, 0x07, 0x58, 0x20, 0xbe, 0xa8, 0x0e,
        0x5d, 0x01, 0x4b, 0x55, 0xa0, 0x14, 0xae, 0x12, 0x6d, 0xa9, 0x87, 0x36,
        0x41, 0x1a, 0x27, 0x1f, 0x01, 0x8d, 0x8e, 0x33, 0x93, 0x45, 0x4b, 0xaa,
        0x71, 0x88, 0x72, 0x8c, 0x36, 0x09, 0x58, 0x20, 0xfc, 0xa3, 0xc9, 0x2b,
        0x41, 0x6f, 0xd5, 0x23, 0x02, 0x48, 0xa2, 0xe7, 0x0a, 0x05, 0x44, 0x1e,
        0x11, 0x9c, 0x7e, 0xe3, 0x6b, 0x6f, 0x28, 0x1e, 0xad, 0x7f, 0xe5, 0x92,
        0xb3, 0x25, 0x87, 0x48, 0x13, 0x58, 0x20, 0xa8, 0xe8, 0x1d, 0x42, 0x7e,
        0x2e, 0x94, 0xe1, 0xd3, 0xc1, 0x0b, 0xef, 0xe0, 0xec, 0x08, 0xa6, 0x5b,
        0x44, 0xad, 0xf6, 0xc1, 0xb1, 0x4d, 0x49, 0x34, 0xca, 0x73, 0xc7, 0x68,
        0xe3, 0x42, 0xf9, 0x06, 0x58, 0x20, 0x89, 0xaf, 0xc8, 0xbc, 0xd0, 0xe8,
        0x81, 0xdd, 0xb2, 0xff, 0x5f, 0x0a, 0x4d, 0x80, 0x26, 0x63, 0xba, 0x39,
        0x4c, 0xdf, 0xee, 0x69, 0xd6, 0xf9, 0xc6, 0xa9, 0x5f, 0x06, 0xfb, 0xb9,
        0x99, 0x3e, 0x15, 0x58, 0x20, 0x42, 0xb1, 0x0a, 0xba, 0xaf, 0x7d, 0x58,
        0xec, 0x3f, 0xee, 0xa1, 0xc9, 0x53, 0xd7, 0x2f, 0xa5, 0x78, 0xa7, 0x42,
        0xb6, 0xcd, 0xc2, 0x8d, 0xe4, 0xc3, 0x58, 0x61, 0xfc, 0x4c, 0xf4, 0xf8,
        0x00, 0x0b, 0x58, 0x20, 0x43, 0x7e, 0xb6, 0xb4, 0x97, 0x64, 0xb8, 0xff,
        0xe7, 0x29, 0x21, 0x1c, 0x21, 0x78, 0x8a, 0x33, 0x24, 0x05, 0xcf, 0xc4,
        0x7d, 0xdf, 0x57, 0x45, 0x71, 0xbb, 0x00, 0xab, 0x6c, 0x8b, 0x79, 0x46,
        0x18, 0x1d, 0x58, 0x20, 0x9a, 0xf5, 0x3e, 0x84, 0xc9, 0xeb, 0x09, 0xf8,
        0x06, 0xbd, 0x48, 0xe8, 0xe4, 0xe0, 0x1b, 0xbb, 0x1e, 0x28, 0x15, 0x88,
        0xc1, 0xea, 0xf4, 0xc8, 0xd0, 0xd9, 0xce, 0x7f, 0x59, 0x03, 0x0c, 0x1a,
        0x18, 0x1e, 0x58, 0x20, 0x87, 0x23, 0x69, 0xa2, 0x27, 0x12, 0x59, 0x32,
        0xa7, 0x61, 0x4d, 0x98, 0x63, 0x21, 0x5c, 0xfe, 0xbf, 0x20, 0xfc, 0xba,
        0x82, 0x30, 0x33, 0x85, 0x71, 0xf3, 0x29, 0x8b, 0xf0, 0xb7, 0x14, 0x42,
        0x18, 0x1f, 0x58, 0x20, 0xce, 0x6c, 0xea, 0x8a, 0x0a, 0x14, 0xc0, 0xb0,
        0x37, 0x04, 0xe9, 0x81, 0x55, 0x3a, 0xf3, 0x7c, 0x34, 0x55, 0x48, 0xfe,
        0xbb, 0x39, 0x85, 0x0d, 0x8e, 0x21, 0x03, 0x58, 0x75, 0xe0, 0x88, 0xcb,
        0x0a, 0x58, 0x20, 0x41, 0xb0, 0x8d, 0xaf, 0x52, 0xc4, 0xb0, 0x9d, 0x9d,
        0x60, 0xb8, 0x75, 0x33, 0xe8, 0xb9, 0xa1, 0x2a, 0x2a, 0xe9, 0xb3, 0x11,
        0x10, 0x59, 0x4e, 0x0e, 0xa9, 0x55, 0xdc, 0x0b, 0x00, 0x6b, 0xc0, 0x77,
        0x6f, 0x72, 0x67, 0x2e, 0x69, 0x73, 0x6f, 0x2e, 0x31, 0x38, 0x30, 0x31,
        0x33, 0x2e, 0x35, 0x2e, 0x31, 0x2e, 0x61, 0x61, 0x6d, 0x76, 0x61, 0xa6,
        0x18, 0x1c, 0x58, 0x20, 0x10, 0x31, 0xf1, 0x32, 0x64, 0xa8, 0xa5, 0xb7,
        0x8b, 0xfa, 0x18, 0x78, 0x99, 0x45, 0x29, 0xbe, 0xed, 0x7d, 0x52, 0x8b,
        0xf2, 0xa0, 0x01, 0xc3, 0x29, 0xdf, 0x54, 0x79, 0x6b, 0xda, 0x79, 0xc4,
        0x18, 0x27, 0x58, 0x20, 0x29, 0xc3, 0xee, 0xdc, 0x37, 0x04, 0x79, 0xa1,
        0xed, 0x0b, 0x57, 0x37, 0x3a, 0xe0, 0xfa, 0xed, 0x5d, 0x7d, 0xc7, 0x74,
        0xdd, 0x75, 0xbd, 0xfd, 0xa2, 0x48, 0xc8, 0xb8, 0x6d, 0x97, 0x20, 0xed,
        0x08, 0x58, 0x20, 0x9e, 0x5b, 0x95, 0x44, 0x7a, 0xe9, 0xf0, 0x50, 0x99,
        0x4b, 0xaf, 0x8a, 0xdb, 0x81, 0x97, 0x84, 0xe6, 0x23, 0xc0, 0x39, 0xe9,
        0x78, 0x29, 0x57, 0x4f, 0x41, 0x26, 0x40, 0x0e, 0x09, 0x77, 0x1c, 0x18,
        0x25, 0x58, 0x20, 0xd0, 0x53, 0x75, 0x45, 0xb5, 0x9c, 0x9d, 0x00, 0xbc,
        0x4a, 0x64, 0xe7, 0x6b, 0x1a, 0x7d, 0x5d, 0xd1, 0x14, 0x43, 0xa4, 0xf0,
        0x7e, 0xff, 0x47, 0xdc, 0xaa, 0xa5, 0x09, 0xc3, 0x1c, 0xf3, 0x19, 0x12,
        0x58, 0x20, 0xde, 0xfb, 0x65, 0x3b, 0x79, 0xb2, 0xa2, 0x43, 0x2f, 0x1f,
        0xb5, 0x67, 0xa2, 0x9d, 0x27, 0xa9, 0xef, 0xf7, 0xe2, 0x5c, 0x83, 0x2d,
        0xb1, 0x64, 0xc8, 0xcb, 0xbe, 0xfc, 0xba, 0x7a, 0x54, 0x6a, 0x18, 0x1a,
        0x58, 0x20, 0x60, 0x49, 0x24, 0x62, 0x3f, 0x82, 0xf6, 0x37, 0x8b, 0xaa,
        0x34, 0x3e, 0xb6, 0x2d, 0x0e, 0x25, 0xba, 0xab, 0x41, 0xd1, 0x1f, 0x69,
        0x23, 0x19, 0xed, 0x61, 0xf5, 0x5b, 0xcf, 0x2e, 0xf1, 0x1b, 0x6d, 0x64,
        0x65, 0x76, 0x69, 0x63, 0x65, 0x4b, 0x65, 0x79, 0x49, 0x6e, 0x66, 0x6f,
        0xa1, 0x69, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4b, 0x65, 0x79, 0xa4,
        0x01, 0x02, 0x20, 0x01, 0x21, 0x58, 0x20, 0x4e, 0x9c, 0x8a, 0xa8, 0x54,
        0x7a, 0x51, 0x52, 0x0b, 0x39, 0xa3, 0xcb, 0x6c, 0x0f, 0x09, 0x9b, 0x23,
        0x49, 0x55, 0xc6, 0x1d, 0x5f, 0x8b, 0x3d, 0xa2, 0x11, 0x29, 0xde, 0x4b,
        0x8d, 0x04, 0x19, 0x22, 0x58, 0x20, 0xa0, 0x88, 0x4a, 0xed, 0xb1, 0x25,
        0xe5, 0x09, 0x7e, 0x86, 0xbf, 0xaa, 0xfa, 0x0c, 0x27, 0xd3, 0xc2, 0x39,
        0x2e, 0x67, 0x82, 0x25, 0x27, 0x33, 0xa6, 0x8f, 0x51, 0x3c, 0xee, 0x78,
        0x55, 0xb7, 0x6c, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x69, 0x74, 0x79, 0x49,
        0x6e, 0x66, 0x6f, 0xa3, 0x66, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0xc0,
        0x78, 0x18, 0x32, 0x30, 0x32, 0x34, 0x2d, 0x30, 0x39, 0x2d, 0x32, 0x36,
        0x54, 0x31, 0x37, 0x3a, 0x35, 0x33, 0x3a, 0x34, 0x31, 0x2e, 0x39, 0x33,
        0x38, 0x5a, 0x69, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x46, 0x72, 0x6f, 0x6d,
        0xc0, 0x78, 0x18, 0x32, 0x30, 0x32, 0x34, 0x2d, 0x30, 0x39, 0x2d, 0x32,
        0x36, 0x54, 0x31, 0x37, 0x3a, 0x35, 0x33, 0x3a, 0x34, 0x31, 0x2e, 0x39,
        0x33, 0x38, 0x5a, 0x6a, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x55, 0x6e, 0x74,
        0x69, 0x6c, 0xc0, 0x78, 0x18, 0x32, 0x30, 0x32, 0x35, 0x2d, 0x30, 0x39,
        0x2d, 0x32, 0x36, 0x54, 0x31, 0x37, 0x3a, 0x35, 0x33, 0x3a, 0x34, 0x31,
        0x2e, 0x39, 0x33, 0x38, 0x5a, 0x58, 0x40, 0xf4, 0x77, 0x60, 0x04, 0x2a,
        0x49, 0x4c, 0x44, 0x0e, 0x81, 0x52, 0x5b, 0x53, 0xa4, 0xff, 0x30, 0x6b,
        0x7d, 0x45, 0x8e, 0x9f, 0xa2, 0xfe, 0x40, 0xe4, 0x89, 0x3a, 0x09, 0xd7,
        0x3a, 0xbc, 0x23, 0xfd, 0x62, 0x39, 0xef, 0x89, 0xac, 0xf1, 0xb2, 0xe7,
        0xe2, 0xb0, 0xa8, 0xd2, 0x5d, 0x8f, 0x27, 0x12, 0xee, 0x60, 0x3c, 0xcb,
        0x0a, 0xd5, 0x6e, 0xeb, 0x5c, 0xb7, 0xfd, 0x78, 0x04, 0xdc, 0xc8, 0x6c,
        0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64,
        0xa2, 0x6a, 0x6e, 0x61, 0x6d, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x73,
        0xd8, 0x18, 0x41, 0xa0, 0x6a, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x41,
        0x75, 0x74, 0x68, 0xa1, 0x6f, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x53,
        0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x84, 0x43, 0xa1, 0x01,
        0x26, 0xa0, 0xf6, 0x58, 0x40, 0xe7, 0x6e, 0x50, 0x02, 0x7d, 0xd7, 0x6d,
        0xa9, 0x12, 0x3c, 0x73, 0x92, 0xbd, 0x4d, 0x64, 0xa9, 0x21, 0x46, 0x85,
        0xdf, 0x7e, 0xf8, 0xdd, 0xca, 0xd9, 0xdc, 0x44, 0xc0, 0xe3, 0x09, 0xa7,
        0x70, 0xda, 0xee, 0x35, 0xe9, 0xe2, 0x49, 0xea, 0xd5, 0x9d, 0x42, 0xaa,
        0x02, 0x0f, 0x4f, 0xaa, 0x0b, 0xdb, 0x78, 0xf0, 0xb8, 0x1d, 0x83, 0xc6,
        0x89, 0xb0, 0x7b, 0x83, 0xce, 0x48, 0x7b, 0x5d, 0x93, 0x66, 0x73, 0x74,
        0x61, 0x74, 0x75, 0x73, 0x00}},

      // ========= Test cases that should fail ==============================

      {false, {X(0, 27), 0x1}},  // invalid count structure
      {false, {X(0, 28), 0x1}},
      {false, {X(0, 29), 0x1}},
      {false, {X(0, 30), 0x1}},
      {false, {X(0, 31), 0x1}},
      {false, {X(5, 3), 0x62}},  // map too short b/c not enough keys
      {false, {X(5, 2), 0x61, 'a', 0x63, 'b', 'c'}},  // map too short
      // array too short, bad key parsing
      {false,
       {X(4, 4), 0x62, 'u', 0x63, 't', 't', 't', 0x62, 'v', 'v', 0x61, 'z'}},
      // failed recursive map of maps
      {false, {0xA1, 0xA1, 0xA1, 1, 1, 0xF4}},
      // invalid date tag len
      {false,
       {0xD9, 0x03, 0xEC, 0x69, 0x31, 0x39, 0x37, 0x31, 0x2D, 0x30, 0x39, 0x2D,
        0x30}},
  };

  for (const auto &test : tests) {
    CborDoc root;
    size_t pos = 0;
    bool got = root.decode(&test.bytes[0], test.bytes.size(), pos, 0);
    EXPECT_EQ(test.valid, got);
    EXPECT_LE(pos, test.bytes.size());
  }
}

TEST(HostDecoderTest, Lookup) {
  CborDoc croot;
  std::vector<uint8_t> mso = {
      0xA6, 0x67, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x63, 0x31, 0x2E,
      0x30, 0x6F, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74, 0x41, 0x6C, 0x67, 0x6F,
      0x72, 0x69, 0x74, 0x68, 0x6D, 0x67, 0x53, 0x48, 0x41, 0x2D, 0x32, 0x35,
      0x36, 0x67, 0x64, 0x6F, 0x63, 0x54, 0x79, 0x70, 0x65, 0x75, 0x6F, 0x72,
      0x67, 0x2E, 0x69, 0x73, 0x6F, 0x2E, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2E,
      0x35, 0x2E, 0x31, 0x2E, 0x6D, 0x44, 0x4C, 0x6C, 0x76, 0x61, 0x6C, 0x75,
      0x65, 0x44, 0x69, 0x67, 0x65, 0x73, 0x74, 0x73, 0xA1, 0x71, 0x6F, 0x72,
      0x67, 0x2E, 0x69, 0x73, 0x6F, 0x2E, 0x31, 0x38, 0x30, 0x31, 0x33, 0x2E,
      0x35, 0x2E, 0x31, 0xA5, 0x01, 0x58, 0x20, 0xAD, 0xF6, 0xA3, 0x33, 0x03,
      0x6A, 0xDE, 0xFC, 0x48, 0x90, 0xDF, 0x38, 0xE0, 0xF7, 0x37, 0x22, 0x90,
      0x85, 0xA9, 0xB0, 0xBA, 0x7C, 0x07, 0x19, 0xD3, 0x92, 0x40, 0x5D, 0x74,
      0x46, 0x23, 0x77, 0x02, 0x58, 0x20, 0xA0, 0xA1, 0x4A, 0x5A, 0xA1, 0xB3,
      0x36, 0x84, 0x4D, 0x8F, 0x8D, 0x14, 0x8E, 0xD4, 0x4F, 0xD2, 0xCC, 0xC6,
      0x6F, 0x54, 0xD8, 0x78, 0x2B, 0x70, 0xFB, 0x77, 0x13, 0xFB, 0x3C, 0x93,
      0xF5, 0x56, 0x03, 0x58, 0x20, 0x97, 0xB0, 0x18, 0x4E, 0xDD, 0xE3, 0x99,
      0xCB, 0x7D, 0xEA, 0x2D, 0x7D, 0x27, 0x9A, 0x45, 0x69, 0x90, 0xD9, 0xF3,
      0x12, 0x46, 0x71, 0x63, 0x78, 0x7E, 0x1B, 0xA7, 0x66, 0x0A, 0x5C, 0x08,
      0x6F, 0x04, 0x58, 0x20, 0xAF, 0x0B, 0x9F, 0xE7, 0x24, 0x5C, 0xA9, 0xA5,
      0x9F, 0x64, 0xB1, 0xAA, 0x82, 0xCC, 0x2C, 0x1A, 0xB1, 0x38, 0x6F, 0x77,
      0x95, 0x64, 0x93, 0x83, 0x62, 0x97, 0xC8, 0xA8, 0x4D, 0x2A, 0xE0, 0xB4,
      0x00, 0x58, 0x20, 0x0D, 0x98, 0x54, 0xDB, 0x51, 0x48, 0x6F, 0xF4, 0x49,
      0x07, 0xBC, 0x61, 0x4F, 0xFA, 0xEA, 0x93, 0xDA, 0xE1, 0xA8, 0x9E, 0xAD,
      0x40, 0x26, 0x3F, 0x90, 0x1A, 0xE6, 0xCE, 0x41, 0x26, 0x46, 0x21, 0x6D,
      0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4B, 0x65, 0x79, 0x49, 0x6E, 0x66,
      0x6F, 0xA1, 0x69, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4B, 0x65, 0x79,
      0xA4, 0x01, 0x02, 0x20, 0x01, 0x21, 0x58, 0x20, 0xC3, 0x14, 0xA7, 0xAB,
      0xBA, 0x07, 0xE4, 0x0E, 0x64, 0xAE, 0x87, 0xDB, 0x4A, 0xD9, 0x71, 0x80,
      0x13, 0xFD, 0x39, 0x8E, 0x6E, 0x23, 0x17, 0xB3, 0x04, 0xF5, 0x7F, 0xC9,
      0xAC, 0xCA, 0xB9, 0xF5, 0x22, 0x58, 0x20, 0xED, 0xB8, 0xB0, 0x23, 0x0C,
      0xCC, 0x98, 0xDD, 0x42, 0xCD, 0xFF, 0x89, 0xA8, 0xD1, 0xE2, 0x5F, 0xF8,
      0xD1, 0xA7, 0xFA, 0x38, 0x9E, 0x92, 0xDC, 0x8F, 0x01, 0xAF, 0x98, 0x5A,
      0x79, 0xEF, 0xCC, 0x6C, 0x76, 0x61, 0x6C, 0x69, 0x64, 0x69, 0x74, 0x79,
      0x49, 0x6E, 0x66, 0x6F, 0xA3, 0x66, 0x73, 0x69, 0x67, 0x6E, 0x65, 0x64,
      0xC0, 0x74, 0x32, 0x30, 0x32, 0x34, 0x2D, 0x30, 0x31, 0x2D, 0x32, 0x35,
      0x54, 0x32, 0x31, 0x3A, 0x31, 0x32, 0x3A, 0x35, 0x39, 0x5A, 0x69, 0x76,
      0x61, 0x6C, 0x69, 0x64, 0x46, 0x72, 0x6F, 0x6D, 0xC0, 0x74, 0x32, 0x30,
      0x32, 0x34, 0x2D, 0x30, 0x31, 0x2D, 0x32, 0x35, 0x54, 0x32, 0x31, 0x3A,
      0x31, 0x32, 0x3A, 0x35, 0x39, 0x5A, 0x6A, 0x76, 0x61, 0x6C, 0x69, 0x64,
      0x55, 0x6E, 0x74, 0x69, 0x6C, 0xC0, 0x74, 0x32, 0x30, 0x32, 0x34, 0x2D,
      0x30, 0x32, 0x2D, 0x32, 0x34, 0x54, 0x32, 0x31, 0x3A, 0x31, 0x32, 0x3A,
      0x35, 0x39, 0x5a};

  size_t pos = 0;
  bool ret = croot.decode(&mso[0], mso.size(), pos, 0);
  EXPECT_TRUE(ret);

  // Perform lookups that should succeed
  size_t ndx;
  std::vector<std::vector<uint8_t>> keys = {
      {'v', 'e', 'r', 's', 'i', 'o', 'n'},
      {'d', 'i', 'g', 'e', 's', 't', 'A', 'l', 'g', 'o', 'r', 'i', 't', 'h',
       'm'},
  };
  for (const auto &key : keys) {
    const CborDoc *got = croot.lookup(mso.data(), key.size(), &key[0], ndx);
    EXPECT_NE(got, nullptr);
  }

  // Perform a cascading series of lookups
  const uint8_t dki[13] = {'d', 'e', 'v', 'i', 'c', 'e', 'K',
                           'e', 'y', 'I', 'n', 'f', 'o'};
  const CborDoc *c_dki = croot.lookup(mso.data(), sizeof(dki), dki, ndx);
  EXPECT_NE(c_dki, nullptr);
  EXPECT_EQ(4u, ndx);

  const uint8_t dk[9] = {'d', 'e', 'v', 'i', 'c', 'e', 'K', 'e', 'y'};
  const CborDoc *c_dk = c_dki[1].lookup(mso.data(), sizeof(dk), dk, ndx);
  EXPECT_NE(c_dk, nullptr);
  EXPECT_EQ(0u, ndx);

  const CborDoc *c_pkx = c_dk[1].lookup_negative(-1, ndx);
  EXPECT_NE(c_pkx, nullptr);
  EXPECT_EQ(2u, ndx);

  const CborDoc *c_00 = c_dk[1].lookup_unsigned(1, ndx);
  EXPECT_NE(c_00, nullptr);
  EXPECT_EQ(0u, ndx);

  // Perform lookups that should fail
  std::vector<std::vector<uint8_t>> not_keys = {
      {'v', 'e', 'r', 's', 'i', 'a', 'n'},
      {'d', 'o', 'g', 'e', 's', 't', 'A', 'l', 'g', 'o', 'r', 'i', 't', 'h',
       'm'},
  };
  for (const auto &key : not_keys) {
    const CborDoc *got = croot.lookup(mso.data(), key.size(), &key[0], ndx);
    EXPECT_EQ(got, nullptr);
  }
  const CborDoc *ptr = c_dk[1].lookup_negative(-4, ndx);
  EXPECT_EQ(ptr, nullptr);
  ptr = c_dk[1].lookup_unsigned(6, ndx);
  EXPECT_EQ(ptr, nullptr);
}

}  // namespace
}  // namespace proofs
